package com.itcast.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//@Component
@Slf4j
//@Aspect
public class AdviceTypeAspect {

    @Pointcut("execution(* com.itcast.service.*.*.*(..))")
    private void pt() {

    }

    //环绕通知
    @Around("pt()")
    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable{
        log.info("环绕通知的前半部分执行了==================");
        Object result = pjp.proceed();
        log.info("环绕通知的后半部分执行了==================");
        return result;
    }

    //前置通知
    @Before("pt()")
    public void beforeAdvice(JoinPoint jp){
        log.info("前置通知执行了==================");
    }

    //后置通知
    @After("pt()")
    public void afterAdvice(JoinPoint jp){
        log.info("后置通知执行了==================");
    }

    //返回后通知
    @AfterReturning("pt()")
    public void afterReturningAdvice(JoinPoint jp){
        log.info("返回后通知执行了==================");
    }

    //异常后通知
    @AfterThrowing("pt()")
    public void afterThrowingAdvice(JoinPoint jp){
        log.info("异常后通知执行了==================");
    }
}
